<template>
    <div class="business-table-list">
        <el-table
                ref="businessTable"
                :data="tableData"
                :height="tableHeight"
                border
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange"
                :default-sort="defaultSort">
            <el-table-column
                    type="selection"
                    show-overflow-tooltip
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="number"
                    label="编号"
                    width="95"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="JGName"
                    label="机构名称"
                    width="250"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="JGLevel"
                    label="机构级别"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="stageStatus"
                    label="阶段状态"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="followStatus"
                    label="跟进状态"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="operator"
                    label="经办人"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="contact"
                    label="联系人"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="auditStatus"
                    label="审核状态"
                    width="95"
                    :filters="auditStatusFilter"
                    :filter-method="filterAuditStatus"
                    filter-placement="bottom-end">
                <template slot-scope="scope">
                    <el-tag :type="auditStatusType(scope.row.auditStatus)" close-transition>
                        {{scope.row.auditStatus}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="handleEdit(scope.$index, scope.row)">编辑
                    </el-button>
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除
                    </el-button>
                    <el-button size="mini" type="primary" @click="handleLook(scope.$index, scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "BusinessTableList",
        props: {
            tableHeight: {
                required: false,
                type: String,
                default: () => {
                    return "550";
                }
            },
            defaultSort: {
                required: false,
                type: Object,
                default: () => {
                    return {prop: 'number', order: 'descending'};
                }
            }
        },
        computed: {
            auditStatusFilter() {
                return [{text: '未审核', value: '未审核'}, {text: '已审核', value: '已审核'}, {text: '审核中', value: '审核中'}];
            },
        },
        data() {
            return {
                multipleSelection: [],
                tableData: [{
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '方案/报价',
                    followStatus: '成交',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '未审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '谈判/合同',
                    followStatus: '成交',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '审核中',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }, {
                    number: '10021',
                    JGName: '山东工业职业学院图书馆',
                    JGLevel: '学校',
                    stageStatus: '需求确定',
                    followStatus: '报价',
                    operator: '夏晓芳',
                    contact: '李小凡',
                    auditStatus: '已审核',
                }]
            }
        },
        methods: {
            auditStatusType(auditStatus) {
                switch (auditStatus) {
                    case '已审核':
                        return 'success';
                    case '未审核':
                        return 'danger';
                    case '审核中':
                        return 'primary';
                }
            },
            /**
             * 编辑
             * @param index
             * @param row
             */
            handleEdit(index, row) {
                console.log(index, row);
            },
            /**
             * 删除
             * @param index
             * @param row
             */
            handleDelete(index, row) {
                console.log(index, row);
            },
            /**
             * 查看
             * @param index
             * @param row
             */
            handleLook(index, row) {
                console.log(index, row);
            },
            /**
             * 状态过滤
             * @param value
             * @param row
             * @returns {boolean}
             */
            filterAuditStatus(value, row) {
                return row.auditStatus === value;
            },
            /**
             * 行背景色处理
             * @param row
             * @param rowIndex
             * @returns {string}
             */
            tableRowClassName({row, rowIndex}) {
                if (row.auditStatus === '未审核') {
                    return 'danger-row';
                } else if (row.auditStatus === '已审核') {
                    return 'success-row';
                } else if (row.auditStatus === '审核中') {
                    return 'default-row';
                }
                return '';
            },
            /**
             * 选中行处理
             * @param val
             */
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style lang="scss">
    .business-table-list {

    }
</style>